﻿using System;

namespace FuzzScript
{
    internal abstract class FuzzyOperator : Node
    {
        internal FuzzyOperator()
        {
            m_SiblingNodes.Add(null);
            m_SiblingNodes.Add(null);
        }

        internal INode LeftNode
        {
            get { return m_SiblingNodes[0]; }
            set { m_SiblingNodes[0] = value; }
        }

        internal INode RightNode
        {
            get { return m_SiblingNodes[1]; }
            set { m_SiblingNodes[1] = value; }
        }

        public override double Execute()
        {
            throw new NotImplementedException();
        }

        public override void AddSibling(INode p_SiblingNode)
        {
            throw new NotImplementedException();
        }

        public override string Generate()
        {
            throw new NotImplementedException();
        }
    }

    internal class OperatorAnd : FuzzyOperator
    {
        public override string ToString()
        {
            return "AND( " + LeftNode + " , " + RightNode + " )";
        }

        public override double Execute()
        {
            return Math.Min(LeftNode.Execute(), RightNode.Execute());
        }

        public override string Generate()
        {
            return "Math.Min(" + LeftNode.Generate() + "," + RightNode.Generate() + ")";
        }
    }

    internal class OperatorOr : FuzzyOperator
    {
        public override string ToString()
        {
            return "OR( " + LeftNode + " , " + RightNode + " )";
        }

        public override double Execute()
        {
            return Math.Max(LeftNode.Execute(), RightNode.Execute());
        }

        public override string Generate()
        {
            return "Math.Max("+LeftNode.Generate()+","+ RightNode.Generate()+")";
        }

    }

}
